{ This unit is part of Scan Antivirus Present.

    Scan Antivirus Present is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Foobar is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.

}
unit usetting;

{$mode objfpc}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  ComCtrls, ExtCtrls, Buttons, StdCtrls, IniPropStorage, EditBtn, Spin, uwizard;

type

  { Tfsettings }

  Tfsettings = class(TForm)
    bbtn_close: TBitBtn;
    BitBtn1: TBitBtn;
    ed_broadc_nmb: TEdit;
    ed_domain: TEdit;
    ed_domain_nmblookup: TEdit;
    ed_net: TEdit;
    ed_net_nbtscan_unix: TEdit;
    ed_rec_eicar_unix: TEdit;
    ed_res_unix: TEdit;
    ed_send_eicar: TEdit;
    ed_eicar_file: TEdit;
    ed_res: TEdit;
    ed_rec_eicar: TEdit;
    ed_send_eicar_unix: TEdit;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    GroupBox4: TGroupBox;
    GroupBox5: TGroupBox;
    GroupBox6: TGroupBox;
    GroupBox7: TGroupBox;
    ini_store_conf: TIniPropStorage;
    Label1: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    PageControl1: TPageControl;
    pcontrol_netbrow: TPageControl;
    Panel1: TPanel;
    pcontrol_netbrow1: TPageControl;
    rb_nbtscan_unix: TRadioButton;
    rb_netview: TRadioButton;
    rb_nbtscan: TRadioButton;
    rb_nmblookup: TRadioButton;
    se_timeout_nbtscan_unix: TSpinEdit;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    TabSheet4: TTabSheet;
    ts_gen_win32: TTabSheet;
    ts_gen_linux: TTabSheet;
    procedure bbtn_closeClick(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure GroupBox4Click(Sender: TObject);
    procedure pcontrol_netbrowChange(Sender: TObject);
    procedure rb_nbtscanChange(Sender: TObject);
    procedure rb_nbtscan_unixChange(Sender: TObject);
    procedure rb_netviewChange(Sender: TObject);
    procedure rb_nmblookupChange(Sender: TObject);
  private
    function validate_field : Boolean;
  public
    procedure set_conf(method : byte; param : String);

  end; 

var
  fsettings: Tfsettings;
  fwizard: Tfwizard;

implementation

uses umain, umethods;
{ Tfsettings }

procedure Tfsettings.bbtn_closeClick(Sender: TObject);
begin
 if rb_nbtscan.Checked then
   begin
     if not validate_field then
       begin
        ShowMessage('Please input network for nbtscan command');
        Abort;
       end;
     if not write_bat_nbtscan_win(ed_net.Text,fmain.workdir) then
     begin
       ShowMessage('Can''t write nbtscan.bat file');
       rb_netview.Checked:=True
     end;
   end;
 if rb_netview.Checked then
    if not write_bat_netview(ed_domain.Text,fmain.workdir) then
       ShowMessage('No puedo escribir el archivo nbtscan.bat');
 close
end;

procedure Tfsettings.BitBtn1Click(Sender: TObject);
begin
  fwizard := Tfwizard.Create(self);
  fwizard.ShowModal
end;

procedure Tfsettings.FormCreate(Sender: TObject);
begin
 {$IFDEF LINUX} //For Linux
   ts_gen_linux.TabVisible:=True;
 {$ENDIF}
 {$IFDEF WIN32} //For MS Windows
   ts_gen_win32.TabVisible:=True;
 {$ENDIF}
 ini_store_conf.IniFileName := fmain.workdir+'scanav.ini';
end;

procedure Tfsettings.GroupBox4Click(Sender: TObject);
begin

end;

procedure Tfsettings.pcontrol_netbrowChange(Sender: TObject);
begin

end;


procedure Tfsettings.rb_nbtscanChange(Sender: TObject);
begin
  if rb_nbtscan.Checked then
     pcontrol_netbrow.TabIndex:=0;
end;

procedure Tfsettings.rb_nbtscan_unixChange(Sender: TObject);
begin
  if rb_nbtscan_unix.Checked then
     pcontrol_netbrow1.TabIndex:=0;
end;

procedure Tfsettings.rb_netviewChange(Sender: TObject);
begin
  if rb_netview.Checked then
     pcontrol_netbrow.TabIndex:=1;
end;

procedure Tfsettings.rb_nmblookupChange(Sender: TObject);
begin
  if rb_nmblookup.Checked then
     pcontrol_netbrow1.TabIndex:=1;
end;

function Tfsettings.validate_field: Boolean;
var
   vok : Boolean;
begin
  vok:=false;
   if Length(ed_net.Text)>= 8 then
      vok:= True;
  Result:= vok;
end;

procedure Tfsettings.set_conf(method: byte; param: String);
begin
  case method of
     0 : begin //Method nbtscan
          {$IFDEF LINUX} //For Linux
           //TODO Por implentar
          {$ENDIF}
          {$IFDEF WIN32} //For MS Windows
             rb_nbtscan.Checked:=True;
             ed_net.Text:=param;
          {$ENDIF}
         end;
     1 : begin //Method netview only on Windows
             rb_netview.Checked:=True;
             ed_domain.Text:=param;
         end;
  end;
end;

initialization
  {$I usetting.lrs}

end.
